<ui:composition xmlns="http://www.w3.org/1999/xhtml"
                xmlns:cc="http://java.sun.com/jsf/composite"
                xmlns:h="http://java.sun.com/jsf/html"
                xmlns:p="http://primefaces.org/ui"
                xmlns:f="http://java.sun.com/jsf/core"
                xmlns:ui="http://java.sun.com/jsf/facelets"
                xmlns:c="http://java.sun.com/jsp/jstl/core">
    <cc:interface>
        <cc:attribute name="edit" type="java.lang.Boolean" default="false"/>
    </cc:interface>

    <cc:implementation>
        <h:form>
            <p:tree value="#{baseCategoryBean.tree}" var="node" id="base_tree" 
                    selectionMode="single"     
                    selection="#{baseCategoryBean.selectNode}"
                    dynamic="true"
                    animate="true">  
                <p:treeNode>  
                    <p:commandLink action="#{node.url}" target="#{node.target}">
                        <h:outputText value="#{node.name}"/>  
                    </p:commandLink>
                </p:treeNode>  
            </p:tree> 
            <p:contextMenu rendered="#{cc.attrs.edit}" for="base_tree">
                <p:menuitem value="增加同级" onclick="dialog_same.show();"/>
                <p:menuitem value="增加子级" onclick="dialog_parent.show();"/>
                <p:menuitem value="删除" actionListener="#{baseCategoryBean.removeNode()}" update="base_tree"/>
            </p:contextMenu>

            <p:dialog widgetVar="dialog_same">
                <p:panelGrid id="same_grid" columns="2">
                    <p:outputLabel value="name" for="id_same_category"/>
                    <h:inputText value="#{baseCategoryBean.entity.name}" id="id_same_category"/>
                    <p:outputLabel value="url" for="id_same_url"/>
                    <h:inputText value="#{baseCategoryBean.entity.url}" id="id_same_url"/>
                    <f:facet name="footer">
                        <p:commandButton value="create"
                                         update="base_tree"
                                         process="same_grid,base_tree,@this"
                                         oncomplete="dialog_same.hide();"
                                         action="#{baseCategoryBean.addSameNode}"/>
                    </f:facet>
                </p:panelGrid>

            </p:dialog>

            <p:dialog widgetVar="dialog_parent">
                <p:panelGrid id="sub_grid" columns="2">
                    <p:outputLabel value="name" for="id_sub_category"/>
                    <h:inputText value="#{baseCategoryBean.entity.name}" id="id_sub_category"/>
                    <p:outputLabel value="url" for="id_sub_url"/>
                    <h:inputText value="#{baseCategoryBean.entity.url}" id="id_sub_url"/>
                    <f:facet name="footer">
                        <p:commandButton value="create"
                                         update="base_tree"
                                         process="sub_grid,base_tree,@this"
                                         oncomplete="dialog_parent.hide();"
                                         action="#{baseCategoryBean.addSubNode}"/>
                    </f:facet>
                </p:panelGrid>
            </p:dialog>            
        </h:form>
    </cc:implementation>
</ui:composition>